s = "LVIII"

s = list(s)  # 将s转换为列表
result = 0
for i in range(len(s)):
    if s[i] == 'I':
        result = result + 1
    if s[i] == 'V':
        result = result + 5
        if s[i - 1] == 'I' and i - 1 >= 0:
            result = result - 2
    if s[i] == 'X':
        result = result + 10
        if s[i - 1] == 'I' and i - 1 >= 0:
            result = result - 2
    if s[i] == 'L':
        result = result + 50
        if s[i - 1] == 'X' and i - 1 >= 0:
            result = result - 20
    if s[i] == 'C':
        result = result + 100
        if s[i - 1] == 'X' and i - 1 >= 0:
            result = result - 20
    if s[i] == 'D':
        result = result + 500
        if s[i - 1] == 'C' and i - 1 >= 0:
            result = result - 200
    if s[i] == 'M':
        result = result + 1000
        if s[i - 1] == 'C' and i - 1 >= 0:
            result = result - 200
print(result)
